package server.commonData;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * sql语句枚举
 * @author King
 *
 */
public class SqlStatementEnum
{
	/**根据帐号查询sql**/
	public final static String QUERY_USERBYACCOUNT = "select * from user where account= ?";
	
	/**创建帐号**/
	public final static String REPLACE_USER = "replace into user(id,account,face,name) values(?,?,?,?)";
	
	/**充值更新元宝**/
	public final static String UPDATE_GOLD = "update user set yuanbao=?,rechargedGold=? where account=?";
	
	/**查询元宝**/
	public final static String QUERY_GOLD = "select yuanbao,rechargedGold from user where account= ?";
	
	/**排行榜金币排名**/
	public final static String RANKING_MONEY_QUERTY = "select name,money from user where money order by money desc limit 50";
	
	/**魅力排名**/
	public final static String RANKING_MEILI_QUERY = "select name,meili from user where meili order by meili desc limit 50";
	
	
	/**
	 * 自动生成sql 
	 * @param map key是表里面的字段  
	 * @param list 值
	 * @return
	 */
	public static String generateReplaceSql(Map<String, Object> map,List list)
	{
		StringBuilder frontSb = new StringBuilder("replace into user(");
		StringBuilder lastSb = new StringBuilder(") values(");
		int lenth = map.size();
		for(Map.Entry<String, Object> entry:map.entrySet())
		{
			lenth--;
			frontSb.append(entry.getKey());
			lastSb.append("?");
			if(lenth!=0)
			{
				frontSb.append(",");
				lastSb.append(",");
			}
			list.add(entry.getValue());
		}
		lastSb.append(")");
		frontSb.append(lastSb);
		return frontSb.toString();
	}
}
